<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>neato! send to phone</title>
        
		<style type="text/css">
			body {
				margin: 0;
				padding: 0;	
			}
			
			#neatoButton {
				border: none;
				outline: none;
				margin: 0;
				padding: 0;
				overflow: hidden;
				text-indent: -99999px;
				display: block;
				width: 169px;
				height: 25px;
				background: url(button.png) no-repeat left top;
			}
			
			#neatoButton:hover {
				background: url(button.png) no-repeat left -26px;	
			}
			
			#input-wrapper {
				display: none;	
			}
			
			#code {
				width: 120px;	
				color: #ccc;
			}
			
			a {
				color: #fff;
				font-family: Helvetica, Arial, sans-serif;	
				font-size: 12px;
				text-decoration: none;
				background: #006;
				border: #ccc;
				padding: 2px;
			}
		</style>
        
	</head>

	<body>
    	<div id="button-wrapper">
	    	<a id="neatoButton" href="#" target="neatoiframe" onmousedown="doNeato();">Send to Phone</a>
        </div>
        <div id="input-wrapper">
        	<input type="text" id="code" value="Enter neato! code..." onfocus="empty();" onblur="fill();"/>
            <a id="codeOK" href="#" onclick="setChannel(); return false;">OK</a>
            <a id="what" target="_blank" href="http://zhephree.com/neato">?</a>
        </div>
        <iframe src="blank.html" width="1" height="1" frameborder="0" style="width:1px;height:1px;position:fixed;bottom:-10px;" scrolling="no" allowtransparency="true" id="neatoiframe" name="neatoiframe"></iframe>
        <script language="javascript">
			//get args
			var s=window.location.search.replace("?","");
			
			var args=s.split("&");
			var bgcolor='ffffff';
			var c='';
			for(var a=0;a<args.length;a++){
				var p=args[a].split("=");
				
				if(p[0]=="bg"){bgcolor=p[1]}
				if(p[0]=="c"){c=encodeURIComponent(p[1]);}
			}
			
			document.body.style.backgroundColor="#"+bgcolor;
			document.getElementById("neatoButton").setAttribute("href","http://pubnub-prod.appspot.com/pubnub-publish?channel=4eb7b6f8-a49c-11df-83df-cb0b90d0ba4b/"+loadChannel()+"&message=%7B%22a%22%3A%22text%22%2C%22c%22%3A%22"+c+"%22%7D&publish_key=0eb9ad11-6ee6-4e94-b9ed-e4b96ce709e8");
			
			
			function doNeato(){
				//find the channel				
				var channel=loadChannel();
				if(!channel || channel==""){
					//prompt for code
					document.getElementById("button-wrapper").style.display="none";
					document.getElementById("input-wrapper").style.display="block";
					
					
					return false;
				}else{						
				}
			}
			
			
			function setCookie(c_name,value,expiredays)
			{
				var exdate=new Date();
				exdate.setDate(exdate.getDate()+expiredays);
				document.cookie=c_name+ "=" +escape(value)+
				((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
			}
			
			function getCookie(c_name)
			{
				if (document.cookie.length>0)
				  {
				  c_start=document.cookie.indexOf(c_name + "=");
				  if (c_start!=-1)
					{
					c_start=c_start + c_name.length+1;
					c_end=document.cookie.indexOf(";",c_start);
					if (c_end==-1) c_end=document.cookie.length;
					return unescape(document.cookie.substring(c_start,c_end));
					}
				  }
				return "";
			}
			
			function empty(){
				if(document.getElementById("code").value=="Enter neato! code..."){
					document.getElementById("code").value='';
					document.getElementById("code").style.color='#000';
				}
			}
			
			function fill() {
				if(document.getElementById("code").value==''){
					document.getElementById("code").style.color='#ccc';
					document.getElementById("code").value='Enter neato! code...';	
				}
			}
			
			function saveChannel(chan){
				  if (supports_html5_storage()) {
					 localStorage.setItem("neato.channel",chan);
				  } else {
					  setCookie("channel",chan,300);
				  }				
			}
			
			function loadChannel(){
				  if (supports_html5_storage()) {
					  if (localStorage.getItem("neato.channel") == null) {
						  return "";
					  } else {
						  return localStorage.getItem("neato.channel");
					  }

				  } else {
					  return getCookie("channel");
				  }				
			}
			
			
			function setChannel(){
				var s = document.createElement('script');			
				s.type = "text/javascript";
				s.src = "http://zhephree.com/neato/get2.php?id="+document.getElementById("code").value;	 
				document.body.appendChild(s);
			}
			
			function gotChannel(chan){
				saveChannel(chan);
				document.getElementById("button-wrapper").style.display="block";
				document.getElementById("input-wrapper").style.display="none";
				document.getElementById("neatoButton").setAttribute("href","http://pubnub-prod.appspot.com/pubnub-publish?channel=4eb7b6f8-a49c-11df-83df-cb0b90d0ba4b/"+chan+"&message=%7B%22a%22%3A%22text%22%2C%22c%22%3A%22"+c+"%22%7D&publish_key=0eb9ad11-6ee6-4e94-b9ed-e4b96ce709e8");

			}
			
			function supports_html5_storage() {
			  try {
				return ('localStorage' in window) && window['localStorage'] !== null;
			  } catch (e) {
				return false;
			  }
			}
			</script>
	</body>
</html>
